﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twi.COMMON.Core;
using Twi.DataAccess.Common;
using Twi.DataAccess.OutInterface;
using System.Data;


namespace Twi.Modules.Demo
{
    public class ModuleCommon
    {
        public static readonly ModuleCommon Instance = new ModuleCommon();

        public bool ExistField(string tableName, string fieldName, string fieldValue)
        {
            return ModuleHelper.DBCommonHelper.ExistField(tableName, fieldName, fieldValue);
        }

        public bool ExistField(string tableName, string fieldName, string fieldValue, string id, string idFieldName = "FID")
        {
            return ModuleHelper.DBCommonHelper.ExistField(tableName, fieldName, fieldValue, id, idFieldName);
        }


        public bool ExistEditSort(string tableName, int? sort, string id, string filterField, string filterFieldValue, string sortField = "FSort", string idField = "FID")
        {
            return ModuleHelper.DBCommonHelper.ExistEditSort(tableName, sort, id, filterField, filterFieldValue, sortField, idField);
        }

        public bool ExistEditSort(string tableName, int? sort, string id, string sortField = "FSort", string idField = "FID")
        {
            return ModuleHelper.DBCommonHelper.ExistEditSort(tableName, sort, id, sortField, idField);
        }

        public bool ExistSort(string tableName, int? sort, string filterField, string filterFieldValue, string sortField = "FSort")
        {
            return ModuleHelper.DBCommonHelper.ExistSort(tableName, sort, filterField, filterFieldValue, sortField);
        }

        public bool ExistSort(string tableName, int? sort, string sortField = "FSort")
        {
            return ModuleHelper.DBCommonHelper.ExistSort(tableName, sort, sortField);
        }

        public int GetMaxSort(string tableName, string filterField, string filterFieldValue, string sortField = "FSort")
        {
            return ModuleHelper.DBCommonHelper.GetMaxSort(tableName, filterField, filterFieldValue, sortField);
        }

        public int GetMaxSort(string tableName, string sortField = "FSort")
        {
            return ModuleHelper.DBCommonHelper.GetMaxSort(tableName, sortField);
        }



        public void Delete(string tableName, string[] ids, string idField = "FID")
        {
            ModuleHelper.DBCommonHelper.Delete(tableName, ids, idField);
        }

        public void Delete(string tableName, string id, string idField = "FID")
        {
            ModuleHelper.DBCommonHelper.Delete(tableName, id, idField);
        }

        public System.Data.DataTable GetAll(string tableName)
        {
            return ModuleHelper.DBCommonHelper.GetAll(tableName);
        }

        public DataTable GetBySimpleCondition(string tableName, Dictionary<string, object> dictCondition, SimpleCondition simpleCondition, string selectFields = "*")
        {
            return ModuleHelper.DBCommonHelper.GetBySimpleCondition(tableName, dictCondition,simpleCondition,selectFields);
        }

        public System.Data.DataTable GetPagingDataByCondition(int start, int limit, string twiData)
        {
            return ModuleHelper.DBCommonHelper.GetPagingDataByCondition(start, limit, twiData);
        }

        public string NewOrEdit(string data)
        {
            return ModuleHelper.DBCommonHelper.NewOrEdit(data);
        }

        public string SimpleNew(string data)
        {
            return ModuleHelper.DBCommonHelper.SimpleNew(data);
        }

        public void SimpleEdit(string tableName, Dictionary<string, object> dictUpdateFields, Dictionary<string, object> dictConditionFields)
        {
            ModuleHelper.DBCommonHelper.SimpleEdit(tableName, dictUpdateFields, dictConditionFields);
        }

        public void SimpleEdit(string data)
        {
            ModuleHelper.DBCommonHelper.SimpleEdit(data);
        }

        public void SimpleNew(string tableName, Dictionary<string, object> dictFields)
        {
            ModuleHelper.DBCommonHelper.SimpleNew(tableName, dictFields);
        }
    }
}
